package com.lebang.controller.sys;

import com.lebang.aop.ConfigRecord;
import com.lebang.common.Login;
import com.lebang.entity.TaskRewards;
import com.lebang.entity.sys.Module;
import com.lebang.service.sys.ApplicationManagementService;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author hwq
 */
@Controller
@RequestMapping("/application")
public class ApplicationManagementController {
    @Autowired
    private ApplicationManagementService applicationManagementService;
    @Login
    @GetMapping("/recordOrder")
    public String recordOrder(){
        return "/application/recordOrder-list";
    }
    @Login
    @PostMapping("/recordOrder")
    @ResponseBody
    public Map<String,Object> recordOrder(Integer page,Integer limit,String type){
        Map<String,Object> returnMap=new HashMap<>(1);
        int startNum = (page - 1) * limit;
        Map<String,Object> queryMap=new HashMap<>(1);
        queryMap.put("type",type);
        returnMap.put("data",applicationManagementService.recordOrderPage(startNum,limit,queryMap));
        returnMap.put("count",applicationManagementService.recordOrderCount(queryMap));
        returnMap.put("code",0);
        return  returnMap;
    }
    @Login
    @PostMapping("/sortSave")
    @ResponseBody
    @ConfigRecord
    public JsonData sortSave(@RequestBody Module module){
        applicationManagementService.updateModule(module);
        return Callback.success("success", "操作成功");
    }
    @PostMapping("/moduleSave")
    @ResponseBody
    @Login
    @ConfigRecord
    public JsonData moduleSave(Module module){
      return applicationManagementService.moduleSave(module);
    }
    @Login
    @PostMapping("/enable")
    @ResponseBody
    @ConfigRecord
    public JsonData enable(@RequestBody Module module) {
        applicationManagementService.updateModule(module);
        return Callback.success("success", "操作成功");
    }
    @GetMapping("/moduleSave")@Login

    public String moduleSave(Long id, Model model,Module module){
        if(id!=null){
            model.addAttribute("item", applicationManagementService.selectByid(id));
        }else {
            model.addAttribute("item", module);
        }

        return "/application/recordOrder-edit";

    }

}
